﻿import java.io.*;

public class Buffer {
	public static void main(String[] args) {
		FileReader fr = null;
		FileWriter fw = null;
		BufferedWriter bw = null;
		BufferedReader br = null;
		try {
			fr = new FileReader("D:\\1.txt");
			br = new BufferedReader(fr);
			fw = new FileWriter("D:\\1.txt");
			bw = new BufferedWriter(fw);
			String str ="你好！我的名字是{name}，我是一只{type}。我的主人是{master}。" ;
			bw.write(str);
			bw.flush();
			StringBuffer sb = new StringBuffer();
			while((str = br.readLine())!=null){
				sb.append(str);
				
			}
			System.out.println("替换前："+sb);
			String s = sb.toString().replace("{name}", "欧欧");
			s = s.replace("{type}", "狗狗");
			s = s.replace("{master}", "三炮");
			System.out.println("替换后："+s);
			bw.write(s);
			bw.flush();
			br.readLine();
			
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block

			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block

			e.printStackTrace();
		}finally{
			try {
				br.close();
				fw.close();	
				fr.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block

				e.printStackTrace();
			}				
		}			
	}
}